package cn.zjh.basic.service.impl;


import cn.zjh.basic.mapper.BaseMapper;
import cn.zjh.basic.query.BaseQuery;
import cn.zjh.basic.service.IBaseService;
import cn.zjh.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
//readOnly = true--配置事务为可读，
//propagation = Propagation.SUPPORTS---配置事务得使用，如果用到就支持使用，没有就不用
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    @Override
    public T findOne(Long id) {
        return baseMapper.findOne(id);
    }

    @Transactional
    @Override
    public void save(T t) {
        baseMapper.save(t);

    }
    @Transactional
    @Override
    public void del(Long id) {

        baseMapper.del(id);

    }
    @Transactional
    @Override
    public void upDate(T t) {
        baseMapper.upDate(t);
    }

    @Override
    public PageList<T> queryPage(BaseQuery baseQuery) {
        Long count = baseMapper.queryCount(baseQuery);
        if (count < 1) {
            return new PageList<>();
        }
        List<T> queryDat = baseMapper.queryData(baseQuery);
        return  new PageList<>(count,queryDat);
    }

    @Transactional
    @Override
    public void patchDelete(Long[] ids) {
        baseMapper.patchDelete(ids);
    }


}
